/*
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.oldroid.apps.getit.ui;



import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.oldroid.apps.getit.R;
import com.oldroid.apps.getit.ui.phone.BrowserActivity;
import com.oldroid.apps.getit.ui.phone.DownloadsActivity;
import com.oldroid.apps.getit.ui.phone.TagsActivity;
import com.oldroid.apps.getit.ui.tablet.BrowserMultiPaneActivity;
import com.oldroid.apps.getit.ui.tablet.DownloadsMultiPaneActivity;
import com.oldroid.apps.getit.util.AnalyticsUtils;
import com.oldroid.apps.getit.util.UIUtils;

public class DashboardFragment extends Fragment {

    public void fireTrackerEvent(String label) {
        AnalyticsUtils.getInstance(getActivity()).trackEvent(
                "Home Screen Dashboard", "Click", label, 0);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_dashboard, container);

        // Attach event handlers
        root.findViewById(R.id.home_btn_downloads).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                fireTrackerEvent("Downloads");
                if (UIUtils.isHoneycombTablet(getActivity())) {
                    startActivity(new Intent(getActivity(), DownloadsMultiPaneActivity.class));
                } else {
                    startActivity(new Intent(getActivity(), DownloadsActivity.class));
                }
                
            }
            
        });

        root.findViewById(R.id.home_btn_tags).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                fireTrackerEvent("Tags");
                // Launch sessions list
                if (UIUtils.isHoneycombTablet(getActivity())) {
                    startActivity(new Intent(getActivity(), DownloadsMultiPaneActivity.class));
                } else {
                    startActivity(new Intent(getActivity(), TagsActivity.class));
                }

            }
        });

        root.findViewById(R.id.home_btn_browser).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                fireTrackerEvent("Browser");
                // Launch list of sessions and vendors the user has starred
                if (UIUtils.isHoneycombTablet(getActivity())) {
                    startActivity(new Intent(getActivity(), BrowserMultiPaneActivity.class));
                } else {
                    startActivity(new Intent(getActivity(), BrowserActivity.class));
                }            
            }
        });

        root.findViewById(R.id.home_btn_settings).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                fireTrackerEvent("Settings");
                startActivity(new Intent(getActivity(), SettingsActivity.class));
            }
        });
        return root;
    }
}
